import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
 export const constantRoutes = [
  {
    path: '/login',
    name:"Login",
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',

    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard', children: ["/dashboard"] }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRouterMap = [
  {
    path: '/Dashboard',
    component: Layout,
    redirect: '/dashboard',
    meta: { title: "统计表", icon: "el-icon-menu", children: ["/platformmanagementstatistics", "/commoditystatistics"] },
    children: [{
      path: '/platformmanagementstatistics',
      name: 'Platformmanagementstatistics',
      component: () => import('@/views/dashboard/platformmanagementstatistics/index'),
      meta: { title: '平台统计', icon: 'dashboard' }
    },
    {
      path: '/commoditystatistics',
      name: 'Commoditystatistics',
      component: () => import('@/views/dashboard/commoditystatistics/index'),
      meta: { title: '商品统计', icon: 'dashboard', }
    }

    ]
  },
  {
    path: '/Admin',
    component: Layout,
    redirect: '/admin',
    meta: { title: '平台管理员管理', icon: 'form', children: ["/admin"] },
    children: [
      {
        path: '/admin',
        name: 'Admin',
        component: () => import('@/views/admin/index'),
        meta: { title: '平台管理员管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/Users',
    component: Layout,
    redirect: '/users',
    meta: { title: '用户', icon: 'form', children: ["/users"] },
    children: [
      {
        path: '/users',
        name: 'Users',
        component: () => import('@/views/users/index'),
        meta: { title: '用户', icon: 'form', }
      }
    ]
  },
  {
    path: '/Managers',
    component: Layout,
    redirect: '/managers',
    meta: { title: '门店管理员管理', icon: 'form', children: ["/managers"] },
    children: [
      {
        path: '/managers',
        name: 'Managers',
        component: () => import('@/views/managers/index'),
        meta: { title: '门店管理员管理', icon: 'form', }
      }
    ]
  },
  {
    path: '/Shops',
    component: Layout,
    redirect: '/shops',
    meta: { title: '门店管理', icon: 'form', children: ["/shops"] },
    children: [
      {
        path: '/shops',
        name: 'Shops',
        component: () => import('@/views/shops/index'),
        meta: { title: '门店管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/Goods',
    component: Layout,
    redirect: '/goods',
    name: 'Goods',
    meta: { title: '商品管理', icon: 'form', children: ["/good", "/server"] },
    children: [
      {
        path: '/good',
        name: 'Good',
        component: () => import('@/views/goods/good/index'),
        meta: { title: '商品管理', icon: 'form' }
      },
      {
        path: '/server',
        name: 'Server',
        component: () => import('@/views/goods/server/index'),
        meta: { title: '服務管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/Ordermanagement',
    component: Layout,
    redirect: '/ordermanagement',
    name: 'Ordermanagement',
    meta: {
      title: '订单管理',
      icon: 'nested',
      children: ["/odergoods", "/orderservices"]
    },
    children: [
      {
        path: '/odergoods',
        component: () => import('@/views/ordermanagement/odergoods/index'),
        name: 'Odergoods',
        meta: { title: 'odergoods', }
      },
      {
        path: '/orderservices',
        component: () => import('@/views/ordermanagement/orderservices/index'),
        name: 'Orderservices',
        meta: { title: 'orderservices', }
      }

    ]
  },
  {
    path: '/Applicationmanagement',
    component: Layout,
    redirect: '/applicationmanagement',
    name: 'Applicationmanagement',
    meta: {
      title: '申请管理',
      icon: 'nested',
      children: ["/managersapply", "/shopsapply", '/goodsapply']
    },
    children: [
      {
        path: '/managersapply',
        component: () => import('@/views/applicationmanagement/managersapply/index'),
        name: 'Managersapply',
        meta: { title: '门店管理员账号申请 ', }
      },
      {
        path: '/shopsapply',
        component: () => import('@/views/applicationmanagement/shopsapply/index'),
        name: 'Shopsapply',
        meta: { title: '门店的申请和注销', }
      },
      {
        path: '/goodsapply',
        component: () => import('@/views/applicationmanagement/goodsapply/index'),
        name: 'Goodsapply',
        meta: { title: '商品上架 ', }
      }

    ]
  },

  {
    // 404 统一跳转到index页
    path: "*",
    redirect: "/login",
    hidden: true
  },

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
